@extends('admin.formLayout')
@if(isset($id))
@section('title','修改作品')
@section('barName','修改作品')
    @else
        @section('title','增加作品')
        @section('barName','增加作品')
    @endif

@php
    $config=config('admin.writing');
@endphp
@section('content')
    <link href="{{asset('js/video/css/video-js.css')}}" rel="stylesheet">
<form class="layui-form" @if(isset($id)) action="{{route('admin.writing_update')}}" @else action="{{route('admin.theme_store')}}" @endif method="post">
    {{csrf_field()}}
    @if(isset($id))
 <input type="hidden" name="id" value="{{$id}}">
    @endif
    <div class="layui-form-item">
        <label class="layui-form-label">作品名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required"  value="{{$model->name or ''}}" autocomplete="off" placeholder="请输入作品名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简短描述</label>
        <div class="layui-input-block">
            <textarea name="desc" placeholder="请输入简短描述" lay-verify="required" class="layui-textarea">{{$model->desc or ''}}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">摄影&绘画</label>
        <div class="layui-input-block">
            @foreach($config as $k=>$v)
                <input type="radio" lay-verify="required"  name="category_id" value="{{$k}}" title="{{$v}}" lay-filter="radio" @if($model->category_id==$k) checked @endif>
            @endforeach


        </div>
    </div>

    <div class="layui-form-item" id="category_0" @if($model->category_id==1) style="display: none" @endif >
        <label class="layui-form-label">主题</label>
        <div class="layui-input-block">
            @foreach($theme as $k=>$v)
                @if($v->category_id==0)
                <input type="radio" name="theme_id" value="{{$v->id}}" lay-filter="radio1" title="{{$v->name}}" @if($model->theme_id==$v->id) checked @endif>
                @endif
            @endforeach
        </div>
    </div>

    <div class="layui-form-item" id="category_1" @if($model->category_id==0) style="display: none" @endif>
        <label class="layui-form-label">主题</label>
        <div class="layui-input-block">
            @foreach($theme as $k=>$v)
                @if($v->category_id==1)
                <input type="radio" name="theme" value="{{$v->id}}" lay-filter="radio1" title="{{$v->name}}" @if($model->theme_id==$v->id) checked @endif>
            @endif
                    @endforeach
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">作品缩略图</label>
        <div class="layui-input-block">
            @include('admin.form.image',['name'=>'thumb_img','value'=>  old('thumb_img') ? old('thumb_img') : $model->thumb_img])
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">作品原图1</label>
        <div class="layui-input-block">
            @include('admin.form.image',['name'=>'master1','value'=> old('master1') ? old('master1') : $model->master[0]])
            </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">作品原图2</label>
        <div class="layui-input-block">
            @include('admin.form.image',['name'=>'master2','value'=> old('master2') ? old('master2') : $model->master[1]])
            </div>
    </div>    <div class="layui-form-item" >
        <label class="layui-form-label">作品原图3</label>
        <div class="layui-input-block">
            @include('admin.form.image',['name'=>'master3','value'=> old('master3') ? old('master3') : $model->master[2]])
            </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">上传视频</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
            <input type="hidden" value="{{$model->video}}" name="video" id="video">
            <video id="my-video" class="video-js" controls preload="none"   height="600"
                   data-setup="{}" @if($model->video=='') style="display: none" @endif>
                <source id="source" src="{{asset('storage/'.$model->video)}}" type="video/mp4">
            </video>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
            <button type="button"  on-click="javascript:location.href='{{route('admin.writing_index')}}'" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>


    <script type="text/javascript">
        var myPlayer = videojs('my-video');
        videojs("my-video").ready(function(){
            var myPlayer = this;
            // myPlayer.play();
        });
    </script>
@endsection